'''
Created on Sep 21, 2011

@author: oabalbin
'''

def pull_down_regions(file,pad):
    '''
    Takes the input pulldown regions for any chip, in bed format.
    Returns the same positions +- pad.
    '''
    ifile=open(file)
    ofile = open(file.replace('.bed','.'+str(pad)+'.bed'),'w')
    for l in ifile:
        f=l.strip('\n').split('\t')
        
        chr,start,end,info=f[0],str(int(f[1])-pad),str(int(f[2])+pad),f[3]
        ol=[chr,start,end,info,'\n']
        
        ofile.write(",".join(ol).replace(',','\t'))

pad=50
file = '/exds/projects/alignment_indexes/exome_targets/agilent/SureSelect_30Mb_Kitv2/Agilent_SureSelect_All_Exon_G3362.v2.hg19.interval_list.bed'
pull_down_regions(file,pad)
